package com.android.lib.download

import java.util.concurrent.ConcurrentHashMap

object DownloadPool {

    /**
     * 等待下载map
     */
    private val prepareTaskMap: ConcurrentHashMap<String, DownloadTask> = ConcurrentHashMap()

    /**
     * 正在下载map
     */
    private val downloadTaskMap: ConcurrentHashMap<String, DownloadTask> = ConcurrentHashMap()


    fun addDownloadTask(key: String, job: DownloadTask) {
        downloadTaskMap[key] = job
    }

    fun addPrepareTask(key: String, job: DownloadTask) {
        prepareTaskMap[key] = job
    }

    fun getPrepareTask(key: String): DownloadTask? {
        return prepareTaskMap[key]
    }

    fun getDownloadTask(key: String): DownloadTask? {
        return downloadTaskMap[key]
    }

    fun getPrepareTaskMap(): ConcurrentHashMap<String, DownloadTask> {
        return prepareTaskMap
    }

    fun getDownloadTaskMap(): ConcurrentHashMap<String, DownloadTask> {
        return downloadTaskMap
    }

    fun removeDownloadTask(key: String?) {
        downloadTaskMap.remove(key)
    }

    fun removePrepareTask(key: String?) {
        prepareTaskMap.remove(key)
    }
}